package com.hspedu.newData.dmsxl.链表;

import com.hspedu.newData.dmsxl.ds.ListNode;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-14 
 * @Version: 1.0
 */

public class LC86分隔链表 {

    public ListNode partition(ListNode head, int x) {

      ListNode small = new ListNode(0);
      ListNode smallHead = small;
      ListNode large = new ListNode(0);
      ListNode largeHead = large;

      while (head!=null){
          if (head.val >= x){
              large.next = head;
              large = large.next;
          }else {
              small.next = head;
              small = small.next;
          }
          head = head.next;
      }

      large.next = null;
      small.next = largeHead.next;
      return smallHead.next;
    }
}
